/*!
 * shallow-clone <https://github.com/jonschlinkert/shallow-clone>
 *
 * Copyright (c) 2015, Jon Schlinkert.
 * Licensed under the MIT License.
 */

'use strict';

import typeOf from './kind-of';

export default function shallowClone(val) {
  switch (typeOf(val)) {
    case 'object':
      return Object.assign({}, val);
    case 'array':
      return val.slice();
    case 'date':
      return new Date(val);
    case 'regexp':
      return cloneRegExp(val);
    default:
      return val;
  }
};

function cloneRegExp(val) {
  var result = new RegExp(val.source, val.flags);
  result.lastIndex = val.lastIndex;
  return result;
}
